<%@page import="com.is.control.HomeworkControl"%>
<%@page import="com.is.model.Homework"%>
<%@page import="com.is.model.HomeworkTime"%>
<%@page import="com.is.control.HomeworkTimeControl"%>
<%@page import="com.is.util.ParamUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.is.util.DateTime"%>
<%@page import="com.is.util.DesData"%>
<%@page import="com.is.servlet.TokenProcessor"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<title>处理听写记录</title>
</head>
<body>
<%                    
                    DesData des = new DesData();
                    String token = ParamUtil.getString(request,"token","AAA");
				    int courseId = ParamUtil.getInt(request, "courseId");
				    int courseClassId = ParamUtil.getInt(request, "ccid");
				    String content = ParamUtil.getString(request, "content","未填写");
				    int size = ParamUtil.getInt(request,"size",0);
				    int classId = ParamUtil.getInt(request,"classId",0);
				    HomeworkTime dt = new HomeworkTime();
				    dt.setContent(content);
				    dt.setCourseClassId(courseClassId);
				    dt.setTime(DateTime.SimpleDate());
				    if(TokenProcessor.AllowCommited(request,token)&&size>0){
				        List<Homework> dics = new ArrayList<Homework>();
				        int timeId =HomeworkTimeControl.insertHomeworkTime(dt);
				        for(int i=0;i<size;i++){
				            int stuId = ParamUtil.getInt(request, "student"+i);
				            String level = ParamUtil.getString(request, "level"+i);
				            Homework d = new Homework();
				            d.setStuId(stuId);
				            d.setLevel(level);
				            d.setTimeId(timeId);
				            dics.add(d);
				        
				        }
				        if(HomeworkControl.insertHomework(dics)){
				        	%>
				            <script>
				            $.dialog({
							    title: '作业录入',
							    content: '系统已将本次作业情况录入',
							    icon: 'succeed',
							    ok: function(){
				            		window.location.href="homework_statistics.jsp?ccid=<%=des.encrypt(String.valueOf(courseClassId))%>";
							    }
							});
				            </script>
				            <%
				        }
				        else{
				        	      HomeworkControl.deleteHomeworkByTimeId(timeId);
				                  %>
				                  <script>
				                  $.dialog({
									    title: '作业录入',
									    content: '抱歉，系统出现错误或您录入的信息有误，本次提交数据均无效，请重试',
									    icon: 'warning',
									    ok: function(){
			                    	  			history.go(-1);
									    }
									});
				                  </script>
				                  <%
				             }
				        }else{
				        	 %>
			                  <script>
			                  $.dialog({
								    title: '作业录入',
								    content: '请不要重复提交此次作业情况，此次提交无效',
								    icon: 'warning',
								    ok: function(){
		                    	  			history.go(-1);
								    }
								});
			                 // alert("请不要重复提交此次作业情况，并检查您的输入是否有误");
			                  //history.go(-1);
			                  </script>
			                  <%
				        }
 %>
</body>
</html>